<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Binduser extends CI_Controller {
	public function index($id)
	{
		$this->load->view('login',array('openid'=>$id));
	}

	public function bind_account(){
		$userid = $this->input->post('form-username');
		$password = $this->input->post('form-password');
		$openid = $this->input->post('openid');
		//$data = GetCookies($userid,$password);
		
		// $result = file_get_contents("http://114.215.88.72/newmysise1/wechat/testUSer/".$userid."/".$password);
		$url = "http://114.215.88.72/newmysise1/wechat/testUSer";
		$result = check_user($url,$userid,$password);
		if($result == "error"){
			echo "<script>alert('用户名或密码错误,请检查');history.go(-1);</script>";
			return ;
		}
		$is_exist = $this->student_model->check_exist($openid);
		if($is_exist){
			echo "<script>alert('该公众号已经绑定过了');document.addEventListener('WeixinJSBridgeReady', function(){ WeixinJSBridge.call('closeWindow'); }, false);</script>";
			
			return;
		}
		$data = array(
			'sid' => $userid,
			'password' => $password,
			'openid'   => $openid
			);
		$this->student_model->bind_user($data);
		echo "<script>alert('绑定成功');document.addEventListener('WeixinJSBridgeReady', function(){ WeixinJSBridge.call('closeWindow'); }, false);</script>";

	}
}

?>